home *** CD-ROM | disk | FTP | other *** search
- /*
- File: FindHammerHead.c
-
- Contains: A snippet that shows how to find the address of the HammerHead chip.
-
- Written by: Quinn "The Eskimo!"
-
- Copyright: © 1997 by Apple Computer, Inc., all rights reserved.
-
- You may incorporate this sample code into your applications without
- restriction, though the sample code has been provided "AS IS" and the
- responsibility for its operation is 100% yours. However, what you are
- not permitted to do is to redistribute the source as "DSC Sample Code"
- after having made changes. If you're going to re-distribute the source,
- we require that you make it clear in the source that the code was
- descended from Apple Sample Code, but that you've made changes.
-
- Change History (most recent first):
-
-
- *** need to support the 'fatman' selector too.
- */
-
- #include <Types.h>
- #include <Errors.h>
- #include <CodeFragments.h>
- #include <NameRegistry.h>
-
- #include "Interleave.h"
-
-
- OSStatus FindHammerHead(void* hammerHeadAddress)
- // Sets hammerHeadAddress to the address of the HammerHead
- // memory controller chip. This routine looks up the
- // HammerHead in the Name Registry, then gets the "reg"
- // property which contains the actual address. If this
- // was successful, it returns noErr. If not, it returns
- // some (hopefully) appropriate error code.
- // The function guards against the absence of NameRegistryLib,
- // so you can run this function on any PPC computer.
- {
- OSStatus err;
- RegEntryIter myIterator;
- Boolean done;
- RegEntryID foundEntry;
- RegPropertyValueSize regPropSize;
-
- // Assume the worst.
- err = unimpErr;
-
- // Check that the link to NameRegistryLib was successfull.
- // If the address of the RegistryEntryIterateCreate routine
- // is nil, then the weak link to NameRegistryLib failed,
- // so we know a) there's no Name Registry for us to call, and
- // b) the machine doesn't have a HammerHead.
-
- if ( (long) RegistryEntryIterateCreate != kUnresolvedCFragSymbolAddress) {
-
- // Create an iterator. By default, the iterator is set
- // to iterate starting at the root of the Name Registry.
- // This means our subsequent RegistryEntrySearch will
- // search the entire Name Registry.
-
- err = RegistryEntryIterateCreate(&myIterator);
- if (err == noErr) {
-
- // Create an 'empty' RegEntryID that RegistryEntrySearch
- // will fill out.
-
- (void) RegistryEntryIDInit(&foundEntry);
-
- // Search for a node in the registry whose "name" property
- // is "hammerhead". This will find the first node called
- // "hammerhead" in the registry. This routine implicitly
- // assumes that there is only one HammerHead in the Name
- // Registry.
-
- err = RegistryEntrySearch(&myIterator, kRegIterContinue, &foundEntry, &done,
- "name", "hammerhead", sizeof("hammerhead"));
-
- if (err == noErr && !done) {
-
- // We found an entry called "hammerhead". Get it's
- // "reg" property into the UInt32 supplied by the caller.
- // Then dispose of the found entry ID.
-
- regPropSize = sizeof(UInt32);
- err = RegistryPropertyGet(&foundEntry, "reg", hammerHeadAddress, ®PropSize);
- (void) RegistryEntryIDDispose(&foundEntry);
-
- } else if (err == noErr) {
- // We didn't find one, but we're about to return
- // noErr, so instead return an appropriate error
- // code.
- err = nrNotFoundErr;
- }
-
- // Dispose of the iterator.
- (void) RegistryEntryIterateDispose(&myIterator);
- }
- }
-
- return (err);
- }
-